package com.wms.function.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wms.function.domain.vo.CategoryInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wms.common.annotation.Log;
import com.wms.common.core.controller.BaseController;
import com.wms.common.core.domain.AjaxResult;
import com.wms.common.enums.BusinessType;
import com.wms.function.domain.TbCategory;
import com.wms.function.service.ITbCategoryService;
import com.wms.common.utils.poi.ExcelUtil;

/**
 * 商品分类Controller
 *
 * @author ruoyi
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/function/category")
@Api(tags = "商品分类的接口")
public class TbCategoryController extends BaseController {
    @Autowired
    private ITbCategoryService tbCategoryService;




    @ApiOperation("查询全部商品分类")
    @GetMapping("/all")
    public AjaxResult listInfo() {
        List<CategoryInfo> category = tbCategoryService.getCategory();
        System.out.println(category.toString());
        return success(category);
    }



/**
 * 查询商品分类列表
 */
@ApiOperation("查询商品分类列表")
@PreAuthorize("@ss.hasPermi('function:category:list')")
@GetMapping("/list")
        public AjaxResult list(TbCategory tbCategory) {
            List<TbCategory> list = tbCategoryService.selectTbCategoryList(tbCategory);
            return success(list);
        }

    /**
     * 导出商品分类列表
     */
    @ApiOperation("导出商品分类列表")
    @PreAuthorize("@ss.hasPermi('function:category:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCategory tbCategory) {
        List<TbCategory> list = tbCategoryService.selectTbCategoryList(tbCategory);
        ExcelUtil<TbCategory> util = new ExcelUtil<TbCategory>(TbCategory. class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
    @ApiOperation("获取商品分类详细信息")
    @PreAuthorize("@ss.hasPermi('function:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "商品分类ID", required = true)
                              @PathVariable("id") Long id) {
        return success(tbCategoryService.selectTbCategoryById(id));
    }

    /**
     * 新增商品分类
     */
    @ApiOperation("新增商品分类")
    @PreAuthorize("@ss.hasPermi('function:category:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "商品分类实体")
                          @RequestBody TbCategory tbCategory) {
        return toAjax(tbCategoryService.insertTbCategory(tbCategory));
    }

    /**
     * 修改商品分类
     */
    @ApiOperation("修改商品分类")
    @PreAuthorize("@ss.hasPermi('function:category:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "商品分类实体")
                           @RequestBody TbCategory tbCategory) {
        return toAjax(tbCategoryService.updateTbCategory(tbCategory));
    }

    /**
     * 删除商品分类
     */
    @ApiOperation("删除商品分类")
    @PreAuthorize("@ss.hasPermi('function:category:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbCategoryService.deleteTbCategoryByIds(ids));
    }
}
